package me.stone.stanimeclient.util

import android.os.Build
import androidx.annotation.RequiresApi
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatterBuilder
import java.util.Calendar
import java.util.Locale

val Calendar.year: Int
    get() = get(Calendar.YEAR)

val Calendar.month: Int
    get() = get(Calendar.MONTH)

val Calendar.dayOfMonth: Int
    get() = get(Calendar.DAY_OF_MONTH)

val Calendar.weekday: Int
    get() = get(Calendar.DAY_OF_WEEK)


/*********************************************************
 * LocalDateTime 格式字符串
 */
private const val DATE_FORMAT_0 = "yyyy-MM-dd HH:mm:ss"
private const val DATE_FORMAT_1 = "yyyy-MM-dd HH:mm"
private const val DATE_FORMAT_2 = "yyyy-MM-dd HH:mm:ss.[SSS]"
private const val DATE_FORMAT_3 = "yyyy-MM-dd"
private const val DATE_FORMAT_4 = "HH:mm:ss"
private const val DATE_FORMAT_5 = "HH:mm"

private val String.dateFormatPattern: DateTimeFormatter
    get() = DateTimeFormatter.ofPattern(this)

/**
 * 时间格式化为 "yyyy-MM-dd HH:mm:ss"
 */
val LocalDate.stringFormat0: String
    get() = DATE_FORMAT_0.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd HH:mm:ss"
 */
val LocalDateTime.stringFormat0: String
    get() = DATE_FORMAT_0.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd HH:mm"
 */
val LocalDate.stringFormat1: String
    get() = DATE_FORMAT_1.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd HH:mm"
 */
val LocalDateTime.stringFormat1: String
    get() = DATE_FORMAT_1.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd HH:mm:ss.[SSS]"
 */
val LocalDate.stringFormat2: String
    get() = DATE_FORMAT_2.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd HH:mm:ss.[SSS]"
 */
val LocalDateTime.stringFormat2: String
    get() = DATE_FORMAT_2.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd"
 */
val LocalDate.stringFormat3: String
    get() = DATE_FORMAT_3.dateFormatPattern.format(this)

/**
 * 时间格式化为 "yyyy-MM-dd"
 */
val LocalDateTime.stringFormat3: String
    get() = DATE_FORMAT_3.dateFormatPattern.format(this)

/**
 * 时间格式化为 "HH:mm:ss"
 */
val LocalDate.stringFormat4: String
    get() = DATE_FORMAT_4.dateFormatPattern.format(this)

/**
 * 时间格式化为 "HH:mm:ss"
 */
val LocalDateTime.stringFormat4: String
    get() = DATE_FORMAT_4.dateFormatPattern.format(this)

/**
 * 时间格式化为 "HH:mm"
 */
val LocalDate.stringFormat5: String
    get() = DATE_FORMAT_5.dateFormatPattern.format(this)

/**
 * 时间格式化为 "HH:mm"
 */
val LocalDateTime.stringFormat5: String
    get() = DATE_FORMAT_5.dateFormatPattern.format(this)